<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

//订单模型
class Orders_model extends CI_Model{
    const TBL_ORDERS = 'orders';
    const TBL_USER = 'user';

    public function list_orders($pay_status=NULL){
        $this->db->select('*');
        $this->db->from(self::TBL_ORDERS);
        $this->db->join(self::TBL_USER,'user.user_id = orders.user_id','left');
        if(isset($pay_status)){
            $this->db->where('orders.pay_status',$pay_status);
        }
        $query = $this->db->order_by('orders.ctime','DESC')->get();
        return $query->result_array();
    }

    public function counts_orders($pay_status=NULL){
        $this->db->select('*');
        $this->db->from(self::TBL_ORDERS);
        $this->db->join(self::TBL_USER,'user.user_id = orders.user_id','left');
        if(isset($pay_status)){
            $this->db->where('orders.pay_status',$pay_status);
        }
        return $this->db->count_all_results();
    }


}